﻿using Npgsql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Runtime.InteropServices;

namespace ConnectPg
{
  public class DbConnect
  {
    public static string Line()
    {
      DataSet ds = new DataSet();
      using (NpgsqlConnection connection = PgConn.NewConnection())
      {
        string sqlStr = "SELECT ST_AsGeoJSON('LINESTRING(120 30,119.5 30,119 30,119 29.5)') as geojson;";
        NpgsqlDataAdapter sqldap = new NpgsqlDataAdapter(sqlStr, connection);
        sqldap.Fill(ds);
      }
      if (ds!=null)
      {
        DataTable dt = ds.Tables[0];
        string result = dt.Rows[0][0].ToString();
        return result;
      }
      else
      {
        return null;
      }
    }

    public static string MultiPoint()
    {
      DataSet ds = new DataSet();
      using (NpgsqlConnection connection = PgConn.NewConnection())
      {
        string sqlStr = "SELECT ST_AsGeoJSON('multipoint(120 30,119.5 30,119 30,119 29.5)') as geojson;";
        NpgsqlDataAdapter sqldap = new NpgsqlDataAdapter(sqlStr, connection);
        sqldap.Fill(ds);
      }
      if (ds != null)
      {
        DataTable dt = ds.Tables[0];
        string result = dt.Rows[0][0].ToString();
        return result;
      }
      else
      {
        return null;
      }
    }
  }
}
